package io.renren.modules.sys.service.impl;

import io.renren.common.utils.Constant;
import io.renren.modules.sys.entity.OnshelvesVOEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.LowershelvesDao;
import io.renren.modules.sys.entity.LowershelvesEntity;
import io.renren.modules.sys.entity.LowershelvesVOEntity;
import io.renren.modules.sys.service.LowershelvesService;


@Service("lowershelvesService")
public class LowershelvesServiceImpl extends ServiceImpl<LowershelvesDao, LowershelvesEntity> implements LowershelvesService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String sheelvesid = (String)params.get("shelvesid");
        String number = (String)params.get("number");
        String reason = (String)params.get("reason");
        String startime = (String)params.get("startime");
        String endtime = (String)params.get("endtime");
        IPage<LowershelvesEntity> page = this.page(
                new Query<LowershelvesEntity>().getPage(params),
                new QueryWrapper<LowershelvesEntity>().like(StringUtils.isNotBlank(number),"lowerNumber",number)
                        .eq(StringUtils.isNotBlank(sheelvesid),"shelvesId",sheelvesid)
                        .eq(StringUtils.isNotBlank(reason),"reason",reason)
                        .gt(StringUtils.isNotBlank(startime),"createtime",startime)
                        .lt(StringUtils.isNotBlank(endtime),"createtime",endtime)
                        .apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );

        return new PageUtils(page);
    }

    @Override
    public LowershelvesVOEntity getInfoById(Integer id){
        LowershelvesVOEntity lowershelvesVOEntity = baseMapper.getInfoById(id);

        return lowershelvesVOEntity;
    }

}
